#!/bin/sh -e

# This script builds and packages everything except the Linux version.
# It should be run in a Cygwin bash shell (under MS Windows, obviously).

unset BCD_MATH
mkdir -p packages

# Rebuild PalmOS version, Conduit, and PalmOS skins
cd palmos
make cleaner
make
make clean
make -e BCD_MATH=1
make clean
make -f Makefile.arm
make clean
make -f Makefile.arm -e BCD_MATH=1
make Free42PalmOSSkins.zip
cd ../conduit
cmd /c build-all.bat
cd ..
rm -rf Free42PalmOS
mkdir Free42PalmOS
cp palmos/README.txt Free42PalmOS
cp palmos/free42bin_68k.prc Free42PalmOS
cp palmos/free42dec_68k.prc Free42PalmOS
cp palmos/free42bin_arm.prc Free42PalmOS
cp palmos/free42dec_arm.prc Free42PalmOS
cp conduit/Release/Free42ConduitInstaller.exe Free42PalmOS
cp conduit/Release/Free42Conduit.dll Free42PalmOS
cp /cygdrive/c/cdk403/Common/Bin/condmgr.dll Free42PalmOS
cp /cygdrive/c/cdk403/Common/Bin/HSAPI.dll Free42PalmOS
zip -r packages/Free42PalmOS.zip Free42PalmOS
rm -rf Free42PalmOS
cp palmos/Free42PalmOSSkins.zip packages/Free42PalmOSSkins.zip

# Rebuild Pocket PC version
cd pocketpc
cmd /c copy-files.bat
make
cmd /c build-all.bat
cd ..
rm -rf Free42PocketPC
mkdir Free42PocketPC
cp pocketpc/README.txt Free42PocketPC
cp pocketpc/Free42Binary.PPC2002_ARM.CAB Free42PocketPC/Free42Binary.cab
cp pocketpc/Free42Decimal.PPC2002_ARM.CAB Free42PocketPC/Free42Decimal.cab
zip -r packages/Free42PocketPC.zip Free42PocketPC
rm -rf Free42PocketPC

# Rebuild Windows version using Visual C++
cd windows
cmd /c build-all.bat
cd ..
rm -rf Free42Windows
mkdir Free42Windows
cp windows/README.txt Free42Windows
cp windows/ReleaseBinary/Free42Binary.exe Free42Windows
cp windows/ReleaseDecimal/Free42Decimal.exe Free42Windows
zip -r packages/Free42Windows.zip Free42Windows
rm -rf Free42Windows

# Rebuild Windows version using MinGW
# cd windows
# cmd /c copy-files.bat
# make cleaner
# PATH="/mingw/bin:$PATH" make
# make clean
# PATH="/mingw/bin:$PATH" make -e BCD_MATH=1
# cd ..
# rm -rf Free42Windows
# mkdir Free42Windows
# cp windows/README.txt Free42Windows
# cp windows/Free42Binary.exe Free42Windows
# cp windows/Free42Decimal.exe Free42Windows
# /mingw/bin/strip Free42Windows/Free42Binary.exe
# /mingw/bin/strip Free42Windows/Free42Decimal.exe
# zip -r packages/Free42Windows.zip Free42Windows
# rm -rf Free42Windows

# Source package, and Windows/Unix and Pocket PC skins packages
mkdir tmp
cd tmp
cvs checkout free42
find . -type d -name CVS -prune -exec rm -rf {} \;
find . -type f -name .cvsignore -exec rm -f {} \;
zip -j ../packages/Free42Skins.zip free42/skins/*
zip -j ../packages/Free42PocketPCSkins.zip free42/ppcskins/*
zip -j ../packages/Free42iPhoneSkins.zip free42/iphoneskins/*
tar cvfz ../packages/free42.tgz free42
cd ..
rm -rf tmp

# "Upstream" source package, for Fedora or other Linux distros
# Has all non-Linux versions, and all skins containing the HP logo, removed
cd upstream
sh ./build-upstream
cd ..

# Wrap it all up...
cd util
cc -o txt2html txt2html.c
cd ..
util/txt2html "Free42 HISTORY" <HISTORY >history.html
util/txt2html "Free42 TODO" <TODO >todo.html
mv history.html todo.html packages
